<template>
	<view>
		<view style="padding-top: 10px;">
			<u-search placeholder="搜索帖子" :showAction="false" @search="search_handle" v-model="index"></u-search>
		</view>
		<post-message v-for="post_id in post_id_list" :post="post_id"></post-message>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				offest: 0,
				index: "",
				post_id_list: []
			}
		},
		async onReachBottom() {
			await this.load_more()
		},
		methods: {
			async search_handle() {
				console.log(this.index)
				this.offest = 0
				this.post_id_list = []
				if (this.index.length) {
					let ret = await uni.request({
						url:getApp().globalData.base_url + `/get/search_post_message/${this.offest}/${this.index}`
					})
					ret.data.forEach(cur_id => {
						this.post_id_list.push(cur_id)
					})
					this.offest = ret.data.length
				}
			},
			async load_more() {
				let ret = await uni.request({
					url:getApp().globalData.base_url + `/${this.offest}/${this.index}`
				})
				this.offest += ret.data.length
				this.data.forEach(cur_id => {
					this.post_id_list.push(cur_id)
				})
			}
		}
	}
</script>

<style>

</style>
